<template>
	<view style="position: relative;">
		<u-navbar title="会员充值" placeholder :autoBack="true" leftIconColor="#E6A5B4" bgColor="#00000000"
			:titleStyle="titleStyle">

		</u-navbar>
		<image src="../static/vip.png" class="topIv" mode="aspectFill"></image>
		<view class="infoV">
			<view class="leftV">
				<view class="nameV">
					<view class="nameTv1">{{userInfo.nickname}}</view>
					<view class="nameTv2" @click="onAgreementClick">充值须知</view>
				</view>
				<view class="weiTv" v-if="userInfo.vip==0">未开通会员卡</view>
				<view class="yuguV">
					<view class="yuguTv1">预估为你节省</view>
					<view class="yuguTv2">539.2</view>
					<view class="yuguTv3">元/年 ></view>
				</view>
			</view>
			<image class="infoIv" :src="userInfo.avatar"></image>
		</view>
		<view class="cenV">
			<view class="titleTv">会员特权</view>
			<view class="srvV">
				<scroll-view class="srvBg" scroll-x="true">
					<view class="itemV" v-for="(item,key) in dataList" :key="key">
						<view class="itemVV">
							<image class="itemIv" :src="item.image"></image>
							<text class="itemTv">{{item.txt}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="titleTv2">充值开通</view>

			<view class="selectV">
				<u-grid :col="2">
					<u-grid-item v-for="(item,key) in moneyList" :key="key">
						<view :class="moneyPos==key?'selectItemVTo':'selectItemV'" @click="onItemClick(item,key)">
							<view class="moneyTv">¥{{item}}</view>
						</view>
					</u-grid-item>
				</u-grid>
			</view>
		</view>

		<view class="xuzhiV">
			<image @click="xieyi=!xieyi" class="xuzhiIv" :src="xieyi?'../static/select_.svg':'../static/select.svg'"></image>
			<view class="xuzhiTv1">我已阅读并同意</view>
			<view class="xuzhiTv2" @click="onAgreementClick">《充值须知》</view>
		</view>
		<view :class="xieyi?'payVTo':'payV'" @click="onPayClick">支付：¥{{money}} 立即开通</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				dataList: [{
					image: "../static/tab1.svg",
					txt: "每单95折"
				}, {
					image: "../static/tab2.svg",
					txt: "勋章成就"
				}, {
					image: "../static/tab3.svg",
					txt: "训练奖励"
				}, {
					image: "../static/tab4.svg",
					txt: "满员等候"
				}, {
					image: "../static/tab5.jpg",
					txt: "探课"
				}],
				moneyList: [],
				userInfo: {},
				moneyPos: 0,
				money: 0,
				xieyi: false
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("user_info");
			this.getRechargeDetail();
		},
		methods: {
			onItemClick(item, index) {
				this.moneyPos = index;
				this.money = item
			},
			getRechargeDetail() {
				this.$api.openVipDetail({
				}).then((res) => {
					this.moneyList = res.price;
					this.moneyPos = 0;
					this.money = this.moneyList[0]
				}).catch((e) => {
					uni.$u.toast("获取配置信息失败");
				})
			},
			onPayClick(){
				if(this.xieyi){
					this.$api.openVip({
						price:this.money
					}).then((res) => {
						this.pay(res.order_id);
					}).catch((e) => {
						uni.$u.toast("充值失败");
					})
				}
			},
			pay(orderid) {
				this.$api.rechargePay({
					order_id: orderid,
				}).then((res) => {
					this.payOrder(res);
				}).catch((e) => {
					uni.$u.toast("充值失败");
				})
			},
			payOrder(payData) {
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: payData.timeStamp,
					nonceStr: payData.nonceStr,
					package: payData.package,
					signType: payData.signType,
					paySign: payData.paySign,
					success: function(res) {
						uni.$u.toast("充值成功");
					},
					fail: function(err) {
						uni.$u.toast("充值失败");
					}
				})
			},
			onAgreementClick() {
				this.$u.route({
					url: '/mine/me/Agreement',
					params: {
						type: 1,
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.topIv {
		width: 100%;
		height: 430rpx;
		position: absolute;
		top: 0rpx;
		left: 0rpx;
		right: 0rpx;
		z-index: -1;
	}

	.infoV {
		background: #000000;
		border-radius: 10rpx;
		border: 2rpx solid #E6A5B4;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		padding: 30rpx;

		.leftV {
			height: 100%;
			display: flex;
			flex: 1;
			margin-right: 30rpx;
			flex-direction: column;

			.nameV {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.nameTv1 {
					font-size: 32rpx;
					color: #FFFFFF;
				}

				.nameTv2 {
					font-size: 24rpx;
					color: #8D8D8D;
					text-decoration: underline;
				}
			}

			.weiTv {
				font-size: 24rpx;
				color: #8D8D8D;
				margin-top: 8rpx;
				flex: 1;
			}

			.yuguV {
				display: flex;
				margin-top: 60rpx;

				.yuguTv1 {
					font-size: 28rpx;
					color: #8D8D8D;
				}

				.yuguTv2 {
					font-size: 28rpx;
					color: #fff;
				}

				.yuguTv3 {
					font-size: 28rpx;
					color: #8D8D8D;
				}
			}
		}

		.infoIv {
			width: 150rpx;
			height: 150rpx;
			border-radius: 50%;
		}
	}

	.cenV {
		background: #1F1F1F;
		border-radius: 10rpx;
		margin-top: 25rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;

		.titleTv {
			font-size: 32rpx;
			color: #FFFFFF;
			margin-left: 30rpx;
			padding-top: 30rpx;
		}

		.srvV {
			margin-top: 40rpx;

			.srvBg {
				width: 100%;
				white-space: nowrap;
				vertical-align: middle;
				overflow: hidden;
				height: 150rpx;
				margin-left: 10rpx;

				.itemV {
					width: 150rpx;
					display: inline-block;
					flex-direction: column;
					align-items: center;

					.itemVV {
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;

						.itemIv {
							width: 110rpx;
							height: 110rpx;
						}

						.itemTv {
							font-size: 24rpx;
							color: #FFFFFF;
							margin-top: 10rpx;
						}
					}

				}
			}
		}

		.titleTv2 {
			font-size: 32rpx;
			color: #FFFFFF;
			margin-left: 30rpx;
			padding-top: 60rpx;
		}

		.selectV {
			padding-bottom: 60rpx;

			.selectItemV {
				width: 90%;
				height: 80rpx;
				background: #1F1F1F;
				border-radius: 10rpx;
				border: 1rpx solid #8D8D8D;
				display: flex;
				margin-top: 30rpx;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.moneyTv {
					font-size: 34rpx;
					color: #8d8d8d;
				}
			}

			.selectItemVTo {
				width: 90%;
				height: 80rpx;
				background: rgba(206, 247, 67, 0.2);
				border-radius: 10rpx;
				border: 1rpx solid #CEF743;
				display: flex;
				margin-top: 30rpx;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.moneyTv {
					font-size: 34rpx;
					color: #CEF743;
				}
			}
		}
	}

	.xuzhiV {
		display: flex;
		margin-top: 35rpx;

		.xuzhiIv {
			width: 30rpx;
			height: 30rpx;
			margin-left: 30rpx;
		}

		.xuzhiTv1 {
			margin-left: 30rpx;
			font-size: 28rpx;
			color: #8D8D8D;
		}

		.xuzhiTv2 {
			font-size: 28rpx;
			color: #8D8D8D;
			text-decoration: underline;
		}
	}

	.payV {
		margin-top: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-bottom: 222rpx;
		height: 100rpx;
		font-size: 32rpx;
		color: #8D8D8D;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #333333;
		border-radius: 10rpx;
	}

	.payVTo {
		margin-top: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-bottom: 222rpx;
		height: 100rpx;
		font-size: 32rpx;
		color: #333;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #CEF743;
		border-radius: 10rpx;
	}
</style>
